Load libraries (packages)

library("respR") ## respirometry/slope analysis
library("tidyverse") ## data manipulation

Set working directory

setwd("[PATH TO DIRECTORY]")

System1 - Dell

Importing data from firesting for resting

preexperiment_date <- "03 May 2023 11 18AM/All"
postexperiment_date <- "03 May 2023 04 04PM/All"

##--- last fish run in trial ---##
experiment_date <- "03 May 2023 12 34PM/Oxygen"
experiment_date2 <- "03 May 2023 12 34PM/All"

firesting <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19)

Cycle_1 <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 

Cycle_last <-read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_date2,"slopes/Cycle_21.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 

System2 - Asus

Importing data from firesting for resting

preexperiment_date_asus <- "03 May 2023 11 12AM/All"
postexperiment_date_asus <- "03 May 2023 04 41PM/All"

##--- last fish run in trial ---##
experiment_date_asus <- "03 May 2023 01 29PM/Oxygen"
experiment_date2_asus <- "03 May 2023 01 29PM/All"

firesting_asus <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_date_asus,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19)

Cycle_1_asus <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_date2_asus,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 

Cycle_last_asus <-read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_date2_asus,"slopes/Cycle_21.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 

Chamber volumes

chamber1_dell = 0.04650
chamber2_dell = 0.04593
chamber3_dell = 0.04977
chamber4_dell = 0.04860 

chamber1_asus = 0.04565
chamber2_asus = 0.04573
chamber3_asus = 0.04551
chamber4_asus = 0.04791

Date_tested="2023-05-03"
Clutch = "85" 
Male = "CARL354" 
Female = "CARL355"
Population = "Arlington reef"
Tank =121 
salinity =36 
Date_analysed = Sys.Date() 

Replicates

1

Enter specimen data

Replicate = 1 
mass = 0.0007254 
chamber = "ch4" 
Swim = "good/good"
chamber_vol = chamber4_dell
system1 = "Dell"
Notes=""

##--- time of trail ---## 
experiment_mmr_date <- "03 May 2023 11 48AM/Oxygen"
experiment_mmr_date2 <- "03 May 2023 11 48AM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",preexperiment_date,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] 0.0003830178

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",postexperiment_date,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] 0.0008287697

Resting metabolic rate

Data manipulation

firesting2 <- firesting |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 1.85
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2$TIME ==Cycle_1$Time[1], firesting$TIME) 
Tstart.dTIME=as.numeric(firesting2[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2$TIME ==tail(Cycle_last$Time, n=1), firesting$TIME) 
Tend.dTIME=as.numeric(firesting2[Tend.row, "dTIME"])  

apoly_insp <- firesting2 |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  5  6  7  9 10 11 12 15 16 17 18 19 21 22 23 24 25
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 1.85
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=255, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from selected replicates... 
## To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 0 rate(s) removed, 21 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 15 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:  11    1     375.0901 -0.02746445 0.997      NA 4880   5112 10081.31
## 2:  13    1     399.6534 -0.02700099 0.998      NA 5863   6096 11160.83
## 3:  15    1     406.7109 -0.02519095 0.997      NA 6851   7085 12241.30
## 4:  18    1     471.7757 -0.02691899 0.996      NA 8333   8566 13860.92
## 5:  19    1     468.3527 -0.02569125 0.998      NA 8827   9060 14401.44
## 6:  21    1     520.6579 -0.02724980 0.993      NA 9813  10046 15481.10
##     endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 10336.40 97.997 90.998 -0.02746445 0.0006536750   -0.02811812 -0.02811812
## 2: 11416.24 98.218 91.276 -0.02700099 0.0007015816   -0.02770257 -0.02770257
## 3: 12496.73 98.295 91.777 -0.02519095 0.0007495236   -0.02594048 -0.02594048
## 4: 14115.68 98.396 91.636 -0.02691899 0.0008213731   -0.02774037 -0.02774037
## 5: 14656.77 98.137 91.595 -0.02569125 0.0008453692   -0.02653662 -0.02653662
## 6: 15736.12 98.445 91.672 -0.02724980 0.0008932680   -0.02814306 -0.02814306
##    oxy.unit time.unit volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.0486 0.0007254   NA 36 27 1.013253 -0.3193648
## 2:     %Air       sec 0.0486 0.0007254   NA 36 27 1.013253 -0.3146450
## 3:     %Air       sec 0.0486 0.0007254   NA 36 27 1.013253 -0.2946312
## 4:     %Air       sec 0.0486 0.0007254   NA 36 27 1.013253 -0.3150743
## 5:     %Air       sec 0.0486 0.0007254   NA 36 27 1.013253 -0.3014021
## 6:     %Air       sec 0.0486 0.0007254   NA 36 27 1.013253 -0.3196481
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -440.2603          NA  mgO2/hr/kg   -440.2603
## 2:   -433.7538          NA  mgO2/hr/kg   -433.7538
## 3:   -406.1638          NA  mgO2/hr/kg   -406.1638
## 4:   -434.3456          NA  mgO2/hr/kg   -434.3456
## 5:   -415.4978          NA  mgO2/hr/kg   -415.4978
## 6:   -440.6508          NA  mgO2/hr/kg   -440.6508
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
85 1 CARL354 CARL355 Arlington reef 121 0.0007254 ch4 Dell 0.0486 2023-05-03 2024-06-19 good/good 36 27 432.9017 0.3140269 0.9964

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.08 1.75
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 15 16 17 19 20 21 22
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.08 1.59
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##      rep rank intercept_b0    slope_b1       rsq density row endrow    time
##   1:  NA    1     214.5053 -0.05859900 0.9937872      NA 105    159 2018.74
##   2:  NA    2     214.4432 -0.05856883 0.9937957      NA 106    160 2019.90
##   3:  NA    3     214.4225 -0.05855981 0.9937149      NA 104    158 2017.34
##   4:  NA    4     214.1716 -0.05843883 0.9934793      NA 103    157 2016.25
##   5:  NA    5     214.1497 -0.05842644 0.9938962      NA 107    161 2021.02
##  ---                                                                       
## 208:  NA  208     119.8160 -0.01126328 0.8300822      NA   5     59 1906.34
## 209:  NA  209     119.5753 -0.01115421 0.8567233      NA   9     63 1910.70
## 210:  NA  210     119.1136 -0.01091416 0.8618837      NA   8     62 1909.61
## 211:  NA  211     119.1251 -0.01091170 0.8583067      NA   6     60 1907.43
## 212:  NA  212     118.8865 -0.01079334 0.8686765      NA   7     61 1908.51
##      endtime    oxy endoxy        rate
##   1: 2078.74 96.171 92.748 -0.05859900
##   2: 2079.90 96.201 92.628 -0.05856883
##   3: 2077.34 96.194 92.830 -0.05855981
##   4: 2076.25 96.221 92.937 -0.05843883
##   5: 2081.02 96.202 92.557 -0.05842644
##  ---                                  
## 208: 1966.34 98.793 97.560 -0.01126328
## 209: 1970.70 98.316 97.423 -0.01115421
## 210: 1969.61 98.444 97.397 -0.01091416
## 211: 1967.43 98.698 97.488 -0.01091170
## 212: 1968.51 98.588 97.426 -0.01079334
## 
## Regressions : 212 | Results : 212 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 212 adjusted rate(s):
## Rate          : -0.058599
## Adjustment    : 0.0003830178
## Adjusted Rate : -0.05898202 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 48 rate(s) removed, 164 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 163 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0  slope_b1       rsq density row endrow    time endtime
## 1:  NA    1     214.5053 -0.058599 0.9937872      NA 105    159 2018.74 2078.74
##       oxy endoxy      rate   adjustment rate.adjusted  rate.input oxy.unit
## 1: 96.171 92.748 -0.058599 0.0003830178   -0.05898202 -0.05898202     %Air
##    time.unit volume      mass area  S  t        P   rate.abs rate.m.spec
## 1:       sec 0.0486 0.0007254   NA 36 27 1.013253 -0.6699161   -923.5127
##    rate.a.spec output.unit rate.output
## 1:          NA  mgO2/hr/kg   -923.5127
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass, 
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
         Notes=Notes, 
                      True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
85 1 CARL354 CARL355 Arlington reef 121 0.0007254 ch4 Dell 0.0486 2023-05-03 2024-06-19 good/good 36 27 432.9017 0.3140269 0.9964 923.5127 0.6699161 0.9937872 490.611 0.3558892

Exporting data

resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 168 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

2

Enter specimen data

Replicate = 2 
mass = 0.0007853 
chamber = "ch3" 
Swim = "good/good"
chamber_vol = chamber3_dell
system1 = "Dell"
Notes=""

##--- time of trail ---## 
experiment_mmr_date <- "03 May 2023 12 06PM/Oxygen"
experiment_mmr_date2 <- "03 May 2023 12 06PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",preexperiment_date,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] 0.0001186327

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",postexperiment_date,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] 0.0004927917

Resting metabolic rate

Data manipulation

firesting2 <- firesting |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 1.85
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2$TIME ==Cycle_1$Time[1], firesting$TIME) 
Tstart.dTIME=as.numeric(firesting2[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2$TIME ==tail(Cycle_last$Time, n=1), firesting$TIME) 
Tend.dTIME=as.numeric(firesting2[Tend.row, "dTIME"])  

apoly_insp <- firesting2 |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  5  6  7  9 10 11 12 15 16 17 18 19 21 22 23 24 25
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 1.85
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=255, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from selected replicates... 
## To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 1 rate(s) removed, 20 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 14 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:   7    1     286.5353 -0.02377651 0.992      NA 2929   3161  7921.74
## 2:   8    1     303.2447 -0.02428248 0.980      NA 3418   3648  8460.02
## 3:  16    1     406.1825 -0.02403394 0.990      NA 7345   7579 12781.02
## 4:  19    1     395.2379 -0.02057908 0.971      NA 8827   9060 14401.44
## 5:  20    1     462.9763 -0.02435206 0.998      NA 9320   9553 14941.47
## 6:  21    1     364.4983 -0.01717572 0.994      NA 9813  10046 15481.10
##     endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1:  8176.28 98.376 91.965 -0.02377651 0.0002653767   -0.02404189 -0.02404189
## 2:  8715.21 98.167 91.526 -0.02428248 0.0002854368   -0.02456792 -0.02456792
## 3: 13036.62 98.560 92.769 -0.02403394 0.0004463783   -0.02448032 -0.02448032
## 4: 14656.77 98.618 93.026 -0.02057908 0.0005067251   -0.02108581 -0.02108581
## 5: 15196.57 98.994 92.978 -0.02435206 0.0005268340   -0.02487889 -0.02487889
## 6: 15736.12 98.412 94.044 -0.01717572 0.0005469308   -0.01772265 -0.01772265
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04977 0.0007853   NA 36 27 1.013253 -0.2796409
## 2:     %Air       sec 0.04977 0.0007853   NA 36 27 1.013253 -0.2857594
## 3:     %Air       sec 0.04977 0.0007853   NA 36 27 1.013253 -0.2847405
## 4:     %Air       sec 0.04977 0.0007853   NA 36 27 1.013253 -0.2452575
## 5:     %Air       sec 0.04977 0.0007853   NA 36 27 1.013253 -0.2893764
## 6:     %Air       sec 0.04977 0.0007853   NA 36 27 1.013253 -0.2061393
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -356.0944          NA  mgO2/hr/kg   -356.0944
## 2:   -363.8857          NA  mgO2/hr/kg   -363.8857
## 3:   -362.5881          NA  mgO2/hr/kg   -362.5881
## 4:   -312.3106          NA  mgO2/hr/kg   -312.3106
## 5:   -368.4916          NA  mgO2/hr/kg   -368.4916
## 6:   -262.4975          NA  mgO2/hr/kg   -262.4975
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
85 2 CARL354 CARL355 Arlington reef 121 0.0007853 ch3 Dell 0.04977 2023-05-03 2024-06-19 good/good 36 27 352.6741 0.276955 0.9862

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.08 1.75
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row,  
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  5  6  7  8  9 11 12 14 15 16 17 18 19 21 22 24 25 26
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.08 1.64
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##      rep rank intercept_b0    slope_b1       rsq density row endrow    time
##   1:  NA    1     271.1713 -0.05765131 0.9987832      NA  80    132 3044.31
##   2:  NA    2     270.9016 -0.05756421 0.9986998      NA  79    131 3043.22
##   3:  NA    3     270.9037 -0.05756367 0.9986755      NA  81    133 3045.39
##   4:  NA    4     272.1027 -0.05749900 0.9937648      NA 213    265 3194.21
##   5:  NA    5     270.4943 -0.05742939 0.9983831      NA  82    134 3046.49
##  ---                                                                       
## 209:  NA  209     218.3967 -0.04026327 0.9907024      NA   5     57 2959.50
## 210:  NA  210     216.6589 -0.03968220 0.9908955      NA   4     56 2957.98
## 211:  NA  211     215.1738 -0.03918443 0.9917760      NA   3     55 2956.90
## 212:  NA  212     213.8200 -0.03873019 0.9929575      NA   2     54 2955.68
## 213:  NA  213     212.5417 -0.03830145 0.9936046      NA   1     53 2954.59
##      endtime    oxy endoxy        rate
##   1: 3104.31 95.517 92.232 -0.05765131
##   2: 3103.22 95.612 92.254 -0.05756421
##   3: 3105.39 95.473 92.223 -0.05756367
##   4: 3254.21 88.241 85.075 -0.05749900
##   5: 3106.49 95.395 92.224 -0.05742939
##  ---                                  
## 209: 3019.50 99.152 96.706 -0.04026327
## 210: 3017.98 99.181 96.720 -0.03968220
## 211: 3016.90 99.226 96.774 -0.03918443
## 212: 3015.68 99.288 96.872 -0.03873019
## 213: 3014.59 99.310 96.993 -0.03830145
## 
## Regressions : 213 | Results : 213 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 213 adjusted rate(s):
## Rate          : -0.05765131
## Adjustment    : 0.0001186327
## Adjusted Rate : -0.05776994 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 0 rate(s) removed, 213 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 212 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     271.1713 -0.05765131 0.9987832      NA  80    132 3044.31
##    endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 3104.31 95.517 92.232 -0.05765131 0.0001186327   -0.05776994 -0.05776994
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04977 0.0007853   NA 36 27 1.013253 -0.6719455
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -855.6546          NA  mgO2/hr/kg   -855.6546
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass, 
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
                      Notes=Notes, 
                      True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
85 2 CARL354 CARL355 Arlington reef 121 0.0007853 ch3 Dell 0.04977 2023-05-03 2024-06-19 good/good 36 27 352.6741 0.276955 0.9862 855.6546 0.6719455 0.9987832 502.9805 0.3949906

Exporting data

resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 169 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

3

Enter specimen data

Replicate = 3 
mass = 0.0006461 
chamber = "ch2" 
Swim = "good/good"
chamber_vol = chamber2_dell
system1 = "Dell"
Notes=""

##--- time of trail ---## 
experiment_mmr_date <- "03 May 2023 12 24PM/Oxygen"
experiment_mmr_date2 <- "03 May 2023 12 24PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",preexperiment_date,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] -0.000391491

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",postexperiment_date,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] 0.0001373295

Resting metabolic rate

Data manipulation

firesting2 <- firesting |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 1.85
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2$TIME ==Cycle_1$Time[1], firesting$TIME) 
Tstart.dTIME=as.numeric(firesting2[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2$TIME ==tail(Cycle_last$Time, n=1), firesting$TIME) 
Tend.dTIME=as.numeric(firesting2[Tend.row, "dTIME"])  

apoly_insp <- firesting2 |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  5  6  7  9 10 11 12 15 16 17 18 19 21 22 23 24 25
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 1.85
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=255, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from selected replicates... 
## To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## Warning: adjust_rate: background rates in 'by' and 'by2' differ in sign (i.e. one is +ve, one is -ve). 
## Ensure this is correct. The 'linear' adjustment has been performed regardless.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 0 rate(s) removed, 21 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 15 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:   2    1     245.5780 -0.02819953 0.985      NA  512    736  5220.69
## 2:  15    1     429.8411 -0.02709569 0.972      NA 6851   7085 12241.30
## 3:  17    1     418.1143 -0.02391574 0.994      NA 7839   8073 13321.08
## 4:  18    1     463.3172 -0.02623190 0.981      NA 8333   8566 13860.92
## 5:  19    1     470.6055 -0.02586135 0.984      NA 8827   9060 14401.44
## 6:  20    1     460.4856 -0.02415805 0.984      NA 9320   9553 14941.47
##     endtime    oxy endoxy        rate    adjustment rate.adjusted  rate.input
## 1:  5476.11 98.008 90.804 -0.02819953 -3.262491e-04   -0.02787328 -0.02787328
## 2: 12496.73 98.543 91.268 -0.02709569  4.331542e-05   -0.02713901 -0.02713901
## 3: 13576.66 99.151 93.181 -0.02391574  1.001589e-04   -0.02401590 -0.02401590
## 4: 14115.68 99.022 92.514 -0.02623190  1.285544e-04   -0.02636046 -0.02636046
## 5: 14656.77 98.115 92.137 -0.02586135  1.570224e-04   -0.02601838 -0.02601838
## 6: 15196.57 99.420 93.610 -0.02415805  1.854434e-04   -0.02434350 -0.02434350
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04593 0.0006461   NA 36 27 1.013253 -0.2991914
## 2:     %Air       sec 0.04593 0.0006461   NA 36 27 1.013253 -0.2913097
## 3:     %Air       sec 0.04593 0.0006461   NA 36 27 1.013253 -0.2577862
## 4:     %Air       sec 0.04593 0.0006461   NA 36 27 1.013253 -0.2829527
## 5:     %Air       sec 0.04593 0.0006461   NA 36 27 1.013253 -0.2792808
## 6:     %Air       sec 0.04593 0.0006461   NA 36 27 1.013253 -0.2613027
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -463.0729          NA  mgO2/hr/kg   -463.0729
## 2:   -450.8740          NA  mgO2/hr/kg   -450.8740
## 3:   -398.9881          NA  mgO2/hr/kg   -398.9881
## 4:   -437.9395          NA  mgO2/hr/kg   -437.9395
## 5:   -432.2563          NA  mgO2/hr/kg   -432.2563
## 6:   -404.4307          NA  mgO2/hr/kg   -404.4307
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple")  
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
85 3 CARL354 CARL355 Arlington reef 121 0.0006461 ch2 Dell 0.04593 2023-05-03 2024-06-19 good/good 36 27 437.7147 0.2828074 0.9812

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.08 1.75
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.08 1.45
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##      rep rank intercept_b0    slope_b1       rsq density row endrow    time
##   1:  NA    1     315.7856 -0.05270349 0.9963981      NA 192    245 4278.16
##   2:  NA    2     315.5619 -0.05265092 0.9962988      NA 193    246 4279.35
##   3:  NA    3     315.5510 -0.05264946 0.9963287      NA 191    244 4277.06
##   4:  NA    4     314.7238 -0.05245554 0.9957682      NA 194    247 4280.44
##   5:  NA    5     314.5495 -0.05241706 0.9962138      NA 190    243 4275.94
##  ---                                                                       
## 207:  NA  207     220.7373 -0.03001547 0.9768774      NA  13     66 4075.01
## 208:  NA  208     220.4365 -0.02994239 0.9763283      NA   9     62 4070.51
## 209:  NA  209     220.3360 -0.02991807 0.9764292      NA  12     65 4073.84
## 210:  NA  210     220.3010 -0.02990964 0.9764043      NA  11     64 4072.74
## 211:  NA  211     220.2017 -0.02988540 0.9763638      NA  10     63 4071.61
##      endtime    oxy endoxy        rate
##   1: 4338.16 90.256 87.184 -0.05270349
##   2: 4339.35 90.200 87.177 -0.05265092
##   3: 4337.06 90.294 87.163 -0.05264946
##   4: 4340.44 90.147 87.198 -0.05245554
##   5: 4335.94 90.352 87.251 -0.05241706
##  ---                                  
## 207: 4135.01 98.366 96.640 -0.03001547
## 208: 4130.51 98.642 96.751 -0.02994239
## 209: 4133.84 98.454 96.667 -0.02991807
## 210: 4132.74 98.498 96.680 -0.02990964
## 211: 4131.61 98.573 96.716 -0.02988540
## 
## Regressions : 211 | Results : 211 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 211 adjusted rate(s):
## Rate          : -0.05270349
## Adjustment    : -0.000391491
## Adjusted Rate : -0.052312 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 0 rate(s) removed, 211 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 210 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     315.7856 -0.05270349 0.9963981      NA 192    245 4278.16
##    endtime    oxy endoxy        rate   adjustment rate.adjusted rate.input
## 1: 4338.16 90.256 87.184 -0.05270349 -0.000391491     -0.052312  -0.052312
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04593 0.0006461   NA 36 27 1.013253 -0.5615162
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -869.0856          NA  mgO2/hr/kg   -869.0856
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass, 
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
                      Notes=Notes, 
                      True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
85 3 CARL354 CARL355 Arlington reef 121 0.0006461 ch2 Dell 0.04593 2023-05-03 2024-06-19 good/good 36 27 437.7147 0.2828074 0.9812 869.0856 0.5615162 0.9963981 431.3709 0.2787087

Exporting data

resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 170 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

4

Enter specimen data

Replicate = 4 
mass = 0.0005931
chamber = "ch1" 
Swim = "good/good"
chamber_vol = chamber1_dell
system1 = "Dell"
Notes=""

##--- time of trail ---## 
experiment_mmr_date <- "03 May 2023 12 34PM/Oxygen"
experiment_mmr_date2 <- "03 May 2023 12 34PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",preexperiment_date,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] -0.0007900342

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",postexperiment_date,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] -0.001106678

Resting metabolic rate

Data manipulation

firesting2 <- firesting |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 1.85
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2$TIME ==Cycle_1$Time[1], firesting$TIME) 
Tstart.dTIME=as.numeric(firesting2[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2$TIME ==tail(Cycle_last$Time, n=1), firesting$TIME) 
Tend.dTIME=as.numeric(firesting2[Tend.row, "dTIME"])  

apoly_insp <- firesting2 |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  5  6  7  9 10 11 12 15 16 17 18 19 21 22 23 24 25
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 1.85
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=255, 
                              by="time", 
                              plot=TRUE)  
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from selected replicates... 
## To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 2 rate(s) removed, 19 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 13 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:   4    1     262.0152 -0.02609023 0.987      NA 1465   1694  6301.40
## 2:  12    1     376.3116 -0.02619586 0.998      NA 5371   5603 10620.92
## 3:  13    1     373.9039 -0.02467541 0.995      NA 5863   6096 11160.83
## 4:  15    1     418.4251 -0.02612406 0.993      NA 6851   7085 12241.30
## 5:  16    1     399.8474 -0.02362228 0.993      NA 7345   7579 12781.02
## 6:  18    1     450.2539 -0.02541885 0.991      NA 8333   8566 13860.92
##     endtime    oxy endoxy        rate    adjustment rate.adjusted  rate.input
## 1:  6556.06 97.128 90.844 -0.02609023 -0.0008631507   -0.02522708 -0.02522708
## 2: 10876.02 98.018 91.554 -0.02619586 -0.0009993065   -0.02519655 -0.02519655
## 3: 11416.24 98.321 92.176 -0.02467541 -0.0010163290   -0.02365908 -0.02365908
## 4: 12496.73 98.319 92.221 -0.02612406 -0.0010503851   -0.02507368 -0.02507368
## 5: 13036.62 97.956 91.914 -0.02362228 -0.0010673994   -0.02255488 -0.02255488
## 6: 14115.68 97.695 91.714 -0.02541885 -0.0011014240   -0.02431743 -0.02431743
##    oxy.unit time.unit volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.0465 0.0005931   NA 36 27 1.013253 -0.2741476
## 2:     %Air       sec 0.0465 0.0005931   NA 36 27 1.013253 -0.2738158
## 3:     %Air       sec 0.0465 0.0005931   NA 36 27 1.013253 -0.2571078
## 4:     %Air       sec 0.0465 0.0005931   NA 36 27 1.013253 -0.2724805
## 5:     %Air       sec 0.0465 0.0005931   NA 36 27 1.013253 -0.2451083
## 6:     %Air       sec 0.0465 0.0005931   NA 36 27 1.013253 -0.2642622
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -462.2283          NA  mgO2/hr/kg   -462.2283
## 2:   -461.6689          NA  mgO2/hr/kg   -461.6689
## 3:   -433.4982          NA  mgO2/hr/kg   -433.4982
## 4:   -459.4175          NA  mgO2/hr/kg   -459.4175
## 5:   -413.2664          NA  mgO2/hr/kg   -413.2664
## 6:   -445.5610          NA  mgO2/hr/kg   -445.5610
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple")  
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
85 4 CARL354 CARL355 Arlington reef 121 0.0005931 ch1 Dell 0.0465 2023-05-03 2024-06-19 good/good 36 27 452.4748 0.2683628 0.9928

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 1.85
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  5  6  7  9 10 11 12 15 16 17 18 19 21 22 23 24 25
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.08 1.36
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##      rep rank intercept_b0    slope_b1       rsq density row endrow    time
##   1:  NA    1     341.0912 -0.05148538 0.9913504      NA 177    230 4837.46
##   2:  NA    2     340.9701 -0.05145928 0.9912272      NA 178    231 4838.56
##   3:  NA    3     340.8482 -0.05143681 0.9911537      NA 176    229 4836.32
##   4:  NA    4     340.7798 -0.05142706 0.9908975      NA 171    224 4830.49
##   5:  NA    5     340.6745 -0.05140498 0.9908551      NA 172    225 4831.83
##  ---                                                                       
## 207:  NA  207     198.6975 -0.02171246 0.9565280      NA  14     67 4651.00
## 208:  NA  208     198.5818 -0.02168969 0.9569482      NA  15     68 4652.21
## 209:  NA  209     197.2987 -0.02166760 0.9597242      NA 112    165 4762.92
## 210:  NA  210     196.7459 -0.02155571 0.9629081      NA 114    167 4765.23
## 211:  NA  211     196.6307 -0.02153006 0.9634711      NA 113    166 4764.14
##      endtime    oxy endoxy        rate
##   1: 4897.46 91.890 89.103 -0.05148538
##   2: 4898.56 91.862 89.057 -0.05145928
##   3: 4896.32 91.927 89.144 -0.05143681
##   4: 4890.49 92.363 89.301 -0.05142706
##   5: 4891.83 92.301 89.266 -0.05140498
##  ---                                  
## 207: 4711.00 98.003 96.256 -0.02171246
## 208: 4712.21 97.934 96.143 -0.02168969
## 209: 4822.92 94.490 92.604 -0.02166760
## 210: 4825.23 94.249 92.524 -0.02155571
## 211: 4824.14 94.346 92.579 -0.02153006
## 
## Regressions : 211 | Results : 211 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 211 adjusted rate(s):
## Rate          : -0.05148538
## Adjustment    : -0.0007900342
## Adjusted Rate : -0.05069534 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 32 rate(s) removed, 179 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 178 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     341.0912 -0.05148538 0.9913504      NA 177    230 4837.46
##    endtime   oxy endoxy        rate    adjustment rate.adjusted  rate.input
## 1: 4897.46 91.89 89.103 -0.05148538 -0.0007900342   -0.05069534 -0.05069534
##    oxy.unit time.unit volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.0465 0.0005931   NA 36 27 1.013253 -0.5509162
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -928.8757          NA  mgO2/hr/kg   -928.8757
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass, 
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
                      Notes=Notes, 
                      True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
85 4 CARL354 CARL355 Arlington reef 121 0.0005931 ch1 Dell 0.0465 2023-05-03 2024-06-19 good/good 36 27 452.4748 0.2683628 0.9928 928.8757 0.5509162 0.9913504 476.4009 0.2825534

Exporting data

resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 171 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

5

Enter specimen data

Replicate = 5 
mass = 0.0004950 
chamber = "ch4" 
Swim = "good/good"
chamber_vol = chamber4_asus
system1 = "Asus"
Notes=""

##--- time of trail ---## 
experiment_mmr_date_asus <- "03 May 2023 12 50PM/Oxygen"
experiment_mmr_date2_asus <- "03 May 2023 12 50PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date_asus,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date2_asus,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",preexperiment_date_asus,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] 0.001103404

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",postexperiment_date_asus,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] -7.916647e-05

Resting metabolic rate

Data manipulation

firesting2_asus <- firesting_asus |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_asus, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1]  1.33 12.86
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2_asus$TIME ==Cycle_1_asus$Time[1], firesting_asus$TIME) 
Tstart.dTIME=as.numeric(firesting2_asus[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2_asus$TIME ==tail(Cycle_last_asus$Time, n=1), firesting_asus$TIME) 
Tend.dTIME=as.numeric(firesting2_asus[Tend.row, "dTIME"])  

apoly_insp <- firesting2_asus |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22
## Minimum and Maximum intervals in uneven Time data: 
## [1]  1.33 12.86
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=255, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## Warning: adjust_rate: background rates in 'by' and 'by2' differ in sign (i.e. one is +ve, one is -ve). 
## Ensure this is correct. The 'linear' adjustment has been performed regardless.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 1 rate(s) removed, 20 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 14 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:   2    1     270.4353 -0.01898515 0.996      NA  429    616  9062.85
## 2:   3    1     310.1069 -0.02192160 0.978      NA  826   1014  9603.71
## 3:   4    1     317.7701 -0.02150424 0.978      NA 1223   1410 10143.91
## 4:   7    1     379.7376 -0.02384564 0.995      NA 2413   2601 11762.86
## 5:  11    1     430.2469 -0.02372610 0.998      NA 4000   4187 13923.90
## 6:  18    1     492.0001 -0.02214726 0.985      NA 6772   6959 17703.58
##     endtime    oxy endoxy        rate    adjustment rate.adjusted  rate.input
## 1:  9317.76 98.596 93.441 -0.01898515  6.689314e-04   -0.01965408 -0.01965408
## 2:  9859.51 98.901 93.869 -0.02192160  5.902041e-04   -0.02251181 -0.02251181
## 3: 10398.55 99.088 93.633 -0.02150424  5.117219e-04   -0.02201596 -0.02201596
## 4: 12018.59 99.030 93.057 -0.02384564  2.761829e-04   -0.02412183 -0.02412183
## 5: 14178.48 99.644 93.857 -0.02372610 -3.803464e-05   -0.02368807 -0.02368807
## 6: 17958.63 99.515 94.547 -0.02214726 -5.877846e-04   -0.02155947 -0.02155947
##    oxy.unit time.unit  volume     mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04791 0.000495   NA 36 27 1.013253 -0.2200611
## 2:     %Air       sec 0.04791 0.000495   NA 36 27 1.013253 -0.2520583
## 3:     %Air       sec 0.04791 0.000495   NA 36 27 1.013253 -0.2465065
## 4:     %Air       sec 0.04791 0.000495   NA 36 27 1.013253 -0.2700852
## 5:     %Air       sec 0.04791 0.000495   NA 36 27 1.013253 -0.2652286
## 6:     %Air       sec 0.04791 0.000495   NA 36 27 1.013253 -0.2413953
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -444.5679          NA  mgO2/hr/kg   -444.5679
## 2:   -509.2087          NA  mgO2/hr/kg   -509.2087
## 3:   -497.9929          NA  mgO2/hr/kg   -497.9929
## 4:   -545.6267          NA  mgO2/hr/kg   -545.6267
## 5:   -535.8153          NA  mgO2/hr/kg   -535.8153
## 6:   -487.6672          NA  mgO2/hr/kg   -487.6672
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
85 5 CARL354 CARL355 Arlington reef 121 0.000495 ch4 Asus 0.04791 2023-05-03 2024-06-19 good/good 36 27 515.2622 0.2550548 0.9868

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 4.05
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 13 14 15 16 17 19 20 21 22
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 1.69
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##      rep rank intercept_b0    slope_b1       rsq density row endrow    time
##   1:  NA    1     389.5643 -0.04685773 0.9957115      NA 104    148 6304.48
##   2:  NA    2     389.3917 -0.04683099 0.9956514      NA 103    147 6303.13
##   3:  NA    3     389.3368 -0.04682283 0.9956321      NA 102    146 6301.78
##   4:  NA    4     389.1713 -0.04679718 0.9955773      NA 101    145 6300.42
##   5:  NA    5     389.1001 -0.04678413 0.9955908      NA 105    149 6305.82
##  ---                                                                       
## 172:  NA  172     267.5034 -0.02773798 0.9881576      NA 175    219 6401.79
## 173:  NA  173     270.2903 -0.02773743 0.9539210      NA   3     47 6166.75
## 174:  NA  174     266.7715 -0.02762421 0.9880863      NA 176    220 6403.15
## 175:  NA  175     264.1131 -0.02674120 0.9431503      NA   2     46 6165.40
## 176:  NA  176     257.9404 -0.02574532 0.9330035      NA   1     45 6163.85
##      endtime    oxy endoxy        rate
##   1: 6364.48 94.114 91.403 -0.04685773
##   2: 6363.13 94.129 91.471 -0.04683099
##   3: 6361.78 94.189 91.520 -0.04682283
##   4: 6360.42 94.254 91.558 -0.04679718
##   5: 6365.82 94.111 91.344 -0.04678413
##  ---                                  
## 172: 6461.79 89.953 88.275 -0.02773798
## 173: 6226.75 98.921 97.459 -0.02773743
## 174: 6463.15 89.889 88.254 -0.02762421
## 175: 6225.40 98.946 97.500 -0.02674120
## 176: 6223.85 99.000 97.559 -0.02574532
## 
## Regressions : 176 | Results : 176 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 176 adjusted rate(s):
## Rate          : -0.04685773
## Adjustment    : 0.001103404
## Adjusted Rate : -0.04796114 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 0 rate(s) removed, 176 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 175 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     389.5643 -0.04685773 0.9957115      NA 104    148 6304.48
##    endtime    oxy endoxy        rate  adjustment rate.adjusted  rate.input
## 1: 6364.48 94.114 91.403 -0.04685773 0.001103404   -0.04796114 -0.04796114
##    oxy.unit time.unit  volume     mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04791 0.000495   NA 36 27 1.013253 -0.5370072
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -1084.863          NA  mgO2/hr/kg   -1084.863
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass,
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
         Notes=Notes, 
         True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
85 5 CARL354 CARL355 Arlington reef 121 0.000495 ch4 Asus 0.04791 2023-05-03 2024-06-19 good/good 36 27 515.2622 0.2550548 0.9868 1084.863 0.5370072 0.9957115 569.6009 0.2819524
### Expor ting data
resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 172 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

6

Enter specimen data

Replicate = 6 
mass = 0.0006303 
chamber = "ch3" 
Swim = "good/good"
chamber_vol = chamber3_asus
system1 = "Asus"
Notes=""

##--- time of trail ---## 
experiment_mmr_date_asus <- "03 May 2023 01 01PM/Oxygen"
experiment_mmr_date2_asus <- "03 May 2023 01 01PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date_asus,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date2_asus,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",preexperiment_date_asus,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] 0.0006286091

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",postexperiment_date_asus,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] -0.001953667

Resting metabolic rate

Data manipulation

firesting2_asus <- firesting_asus |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_asus, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1]  1.33 12.86
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2_asus$TIME ==Cycle_1_asus$Time[1], firesting_asus$TIME) 
Tstart.dTIME=as.numeric(firesting2_asus[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2_asus$TIME ==tail(Cycle_last_asus$Time, n=1), firesting_asus$TIME) 
Tend.dTIME=as.numeric(firesting2_asus[Tend.row, "dTIME"])  

apoly_insp <- firesting2_asus |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22
## Minimum and Maximum intervals in uneven Time data: 
## [1]  1.33 12.86
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=245, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## Warning: adjust_rate: background rates in 'by' and 'by2' differ in sign (i.e. one is +ve, one is -ve). 
## Ensure this is correct. The 'linear' adjustment has been performed regardless.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 1 rate(s) removed, 20 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 14 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:  11    1     482.7358 -0.02762375 0.999      NA 4000   4180 13923.90
## 2:  13    1     470.0638 -0.02480900 0.985      NA 4792   4972 15003.65
## 3:  14    1     477.6925 -0.02439853 0.995      NA 5189   5369 15544.22
## 4:  17    1     533.1736 -0.02531423 0.967      NA 6377   6557 17163.08
## 5:  18    1     589.0147 -0.02767009 0.991      NA 6772   6952 17703.58
## 6:  21    1     662.3644 -0.02919473 0.996      NA 7944   8124 19322.84
##     endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 14169.01 98.148 91.412 -0.02762375 -0.001862347   -0.02576140 -0.02576140
## 2: 15248.58 98.069 91.957 -0.02480900 -0.002205230   -0.02260377 -0.02260377
## 3: 15789.13 98.492 92.454 -0.02439853 -0.002376903   -0.02202163 -0.02202163
## 4: 17408.24 98.978 91.714 -0.02531423 -0.002891067   -0.02242316 -0.02242316
## 5: 17949.07 98.983 92.270 -0.02767009 -0.003062773   -0.02460732 -0.02460732
## 6: 19568.58 98.274 90.821 -0.02919473 -0.003577064   -0.02561766 -0.02561766
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04551 0.0006303   NA 36 27 1.013253 -0.2739938
## 2:     %Air       sec 0.04551 0.0006303   NA 36 27 1.013253 -0.2404098
## 3:     %Air       sec 0.04551 0.0006303   NA 36 27 1.013253 -0.2342182
## 4:     %Air       sec 0.04551 0.0006303   NA 36 27 1.013253 -0.2384889
## 5:     %Air       sec 0.04551 0.0006303   NA 36 27 1.013253 -0.2617192
## 6:     %Air       sec 0.04551 0.0006303   NA 36 27 1.013253 -0.2724650
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -434.7038          NA  mgO2/hr/kg   -434.7038
## 2:   -381.4212          NA  mgO2/hr/kg   -381.4212
## 3:   -371.5980          NA  mgO2/hr/kg   -371.5980
## 4:   -378.3737          NA  mgO2/hr/kg   -378.3737
## 5:   -415.2296          NA  mgO2/hr/kg   -415.2296
## 6:   -432.2784          NA  mgO2/hr/kg   -432.2784
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
85 6 CARL354 CARL355 Arlington reef 121 0.0006303 ch3 Asus 0.04551 2023-05-03 2024-06-19 good/good 36 27 408.4013 0.2574154 0.9876

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 4.05
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  8  9 10 11 13 14 15 16 17 18 19 20 21 22
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 1.55
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##      rep rank intercept_b0    slope_b1       rsq density row endrow    time
##   1:  NA    1     628.4789 -0.07685386 0.9826511      NA 131    176 6979.12
##   2:  NA    2     627.8703 -0.07676873 0.9823770      NA 130    175 6977.78
##   3:  NA    3     627.5375 -0.07671783 0.9821794      NA 132    177 6980.46
##   4:  NA    4     626.2743 -0.07654259 0.9816541      NA 129    174 6976.43
##   5:  NA    5     624.4874 -0.07628095 0.9805773      NA 133    178 6981.85
##  ---                                                                       
## 173:  NA  173     208.5667 -0.01624419 0.9485980      NA   5     50 6807.77
## 174:  NA  174     205.0036 -0.01572255 0.9557615      NA   4     49 6806.42
## 175:  NA  175     204.3312 -0.01562350 0.9577850      NA   3     48 6805.05
## 176:  NA  176     204.2825 -0.01561571 0.9628247      NA   1     46 6802.16
## 177:  NA  177     204.0873 -0.01558709 0.9626013      NA   2     47 6803.50
##      endtime    oxy endoxy        rate
##   1: 7039.12 91.897 87.739 -0.07685386
##   2: 7037.78 91.963 87.792 -0.07676873
##   3: 7040.46 91.851 87.705 -0.07671783
##   4: 7036.43 92.010 87.859 -0.07654259
##   5: 7041.85 91.798 87.710 -0.07628095
##  ---                                  
## 173: 6867.77 98.075 96.818 -0.01624419
## 174: 6866.42 98.067 96.923 -0.01572255
## 175: 6865.05 98.088 96.960 -0.01562350
## 176: 6862.16 98.058 97.138 -0.01561571
## 177: 6863.50 98.058 97.121 -0.01558709
## 
## Regressions : 177 | Results : 177 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 177 adjusted rate(s):
## Rate          : -0.07685386
## Adjustment    : 0.0006286091
## Adjusted Rate : -0.07748247 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 5 rate(s) removed, 172 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 171 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     628.4789 -0.07685386 0.9826511      NA 131    176 6979.12
##    endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 7039.12 91.897 87.739 -0.07685386 0.0006286091   -0.07748247 -0.07748247
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04551 0.0006303   NA 36 27 1.013253 -0.8240903
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -1307.457          NA  mgO2/hr/kg   -1307.457
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass,
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
         Notes=Notes, 
         True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
85 6 CARL354 CARL355 Arlington reef 121 0.0006303 ch3 Asus 0.04551 2023-05-03 2024-06-19 good/good 36 27 408.4013 0.2574154 0.9876 1307.457 0.8240903 0.9826511 899.0559 0.5666749
### Expor ting data
resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 173 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

7

Enter specimen data

Replicate = 7 
mass = 0.0007266 
chamber = "ch2" 
Swim = "good/good"
chamber_vol = chamber2_asus
system1 = "Asus"
Notes=""

##--- time of trail ---## 
experiment_mmr_date_asus <- "03 May 2023 01 29PM/Oxygen"
experiment_mmr_date2_asus <- "03 May 2023 01 29PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date_asus,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date2_asus,"slopes/Cycle_2.txt"), # custom
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",preexperiment_date_asus,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] 0.004853167

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",postexperiment_date_asus,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] 8.312636e-05

Resting metabolic rate

Data manipulation

firesting2_asus <- firesting_asus |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_asus, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1]  1.33 12.86
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2_asus$TIME ==Cycle_1_asus$Time[1], firesting_asus$TIME) 
Tstart.dTIME=as.numeric(firesting2_asus[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2_asus$TIME ==tail(Cycle_last_asus$Time, n=1), firesting_asus$TIME) 
Tend.dTIME=as.numeric(firesting2_asus[Tend.row, "dTIME"])  

apoly_insp <- firesting2_asus |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22
## Minimum and Maximum intervals in uneven Time data: 
## [1]  1.33 12.86
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=245, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 0 rate(s) removed, 21 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 15 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:   1    1     331.4023 -0.02750094 0.973      NA   34    214  8523.72
## 2:  16    1     612.9263 -0.03088297 0.998      NA 5981   6161 16623.86
## 3:  17    1     633.7635 -0.03109029 0.998      NA 6377   6557 17163.08
## 4:  19    1     656.3962 -0.03051069 0.996      NA 7160   7340 18243.92
## 5:  20    1     698.6063 -0.03190022 0.993      NA 7556   7735 18783.94
## 6:  21    1     693.1124 -0.03069272 0.995      NA 7944   8124 19322.84
##     endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1:  8768.84 97.608 91.138 -0.02750094  0.003419820   -0.03092076 -0.03092076
## 2: 16869.18 99.417 91.937 -0.03088297 -0.001332175   -0.02955079 -0.02955079
## 3: 17408.24 99.887 92.421 -0.03109029 -0.001648461   -0.02944183 -0.02944183
## 4: 18489.14 99.471 92.507 -0.03051069 -0.002282552   -0.02822813 -0.02822813
## 5: 19028.23 99.170 91.745 -0.03190022 -0.002599082   -0.02930114 -0.02930114
## 6: 19568.58 99.657 92.431 -0.03069272 -0.002915652   -0.02777706 -0.02777706
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04573 0.0007266   NA 36 27 1.013253 -0.3304577
## 2:     %Air       sec 0.04573 0.0007266   NA 36 27 1.013253 -0.3158165
## 3:     %Air       sec 0.04573 0.0007266   NA 36 27 1.013253 -0.3146520
## 4:     %Air       sec 0.04573 0.0007266   NA 36 27 1.013253 -0.3016809
## 5:     %Air       sec 0.04573 0.0007266   NA 36 27 1.013253 -0.3131484
## 6:     %Air       sec 0.04573 0.0007266   NA 36 27 1.013253 -0.2968602
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -454.8000          NA  mgO2/hr/kg   -454.8000
## 2:   -434.6497          NA  mgO2/hr/kg   -434.6497
## 3:   -433.0471          NA  mgO2/hr/kg   -433.0471
## 4:   -415.1953          NA  mgO2/hr/kg   -415.1953
## 5:   -430.9777          NA  mgO2/hr/kg   -430.9777
## 6:   -408.5607          NA  mgO2/hr/kg   -408.5607
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
85 7 CARL354 CARL355 Arlington reef 121 0.0007266 ch2 Asus 0.04573 2023-05-03 2024-06-19 good/good 36 27 433.734 0.3151511 0.9916

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1]  1.33 12.86
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  2  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 20 21 22 23
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 1.65
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##      rep rank intercept_b0    slope_b1       rsq density row endrow    time
##   1:  NA    1     693.5920 -0.06591917 0.9987069      NA   2     47 9020.51
##   2:  NA    2     693.1087 -0.06586545 0.9986520      NA   3     48 9021.88
##   3:  NA    3     692.1996 -0.06576567 0.9985295      NA   1     46 9019.15
##   4:  NA    4     691.3318 -0.06566872 0.9983779      NA   4     49 9023.22
##   5:  NA    5     688.4836 -0.06535356 0.9977867      NA   5     50 9024.56
##  ---                                                                       
## 172:  NA  172     372.4135 -0.03067395 0.9425314      NA  72    117 9116.14
## 173:  NA  173     370.9782 -0.03065823 0.9915312      NA 163    208 9240.07
## 174:  NA  174     371.9560 -0.03062813 0.9428069      NA  75    120 9120.22
## 175:  NA  175     370.7279 -0.03049117 0.9450784      NA  73    118 9117.50
## 176:  NA  176     370.4182 -0.03045877 0.9452899      NA  74    119 9118.86
##      endtime    oxy endoxy        rate
##   1: 9080.51 98.935 95.052 -0.06591917
##   2: 9081.88 98.906 95.002 -0.06586545
##   3: 9079.15 98.946 95.122 -0.06576567
##   4: 9083.22 98.825 94.978 -0.06566872
##   5: 9084.56 98.731 94.960 -0.06535356
##  ---                                  
## 172: 9176.14 93.264 90.710 -0.03067395
## 173: 9300.07 87.871 85.757 -0.03065823
## 174: 9180.22 92.979 90.491 -0.03062813
## 175: 9177.50 93.186 90.638 -0.03049117
## 176: 9178.86 93.078 90.561 -0.03045877
## 
## Regressions : 176 | Results : 176 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 176 adjusted rate(s):
## Rate          : -0.06591917
## Adjustment    : 0.004853167
## Adjusted Rate : -0.07077234 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 16 rate(s) removed, 160 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 159 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1      693.592 -0.06591917 0.9987069      NA   2     47 9020.51
##    endtime    oxy endoxy        rate  adjustment rate.adjusted  rate.input
## 1: 9080.51 98.935 95.052 -0.06591917 0.004853167   -0.07077234 -0.07077234
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04573 0.0007266   NA 36 27 1.013253 -0.7563612
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -1040.959          NA  mgO2/hr/kg   -1040.959
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass,
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
         Notes=Notes, 
         True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
85 7 CARL354 CARL355 Arlington reef 121 0.0007266 ch2 Asus 0.04573 2023-05-03 2024-06-19 good/good 36 27 433.734 0.3151511 0.9916 1040.959 0.7563612 0.9987069 607.2255 0.4412101
### Expor ting data
resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 174 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)